package org.sccba.demo01.sequece;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.sccba.demo01.Product;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;

public class Test {

	public static void main(String[] args) throws Exception {
		
		//创建一个配置类
				Configuration cfg = new Configuration(Configuration.VERSION_2_3_29);
				
				cfg.setDirectoryForTemplateLoading(new File("G:\\EclipseWorkspaces\\freemarker\\demo01\\src\\resource\\templates"));
				
				cfg.setDefaultEncoding("UTF-8");
		        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
		        cfg.setLogTemplateExceptions(false);
		        cfg.setWrapUncheckedExceptions(true);
		        cfg.setFallbackOnNullLoopVariable(false);
				
				//创建一个模型数据
		        
		        
		        Map<String, String> fieldMap = new HashMap<String, String>();
		        fieldMap.put("field0", "USERNAME,fh,String,fh,用户名,fh,否,fh,无,fh,30,fh,0");
		        fieldMap.put("field1", "PHOTO0,fh,String,fh,原图,fh,否,fh,无,fh,100,fh,0");
		        fieldMap.put("field2", "PHOTO1,fh,String,fh,头像1,fh,否,fh,无,fh,100,fh,0");
		        fieldMap.put("field3", "PHOTO2,fh,String,fh,头像2,fh,否,fh,无,fh,100,fh,0");
		        fieldMap.put("field4", "PHOTO3,fh,String,fh,头像3,fh,否,fh,无,fh,100,fh,0");
				
				List<String[]> fieldList = new ArrayList<String[]>();   	//属性集合			========参数4
				for(int i=0; i< fieldMap.size(); i++){
					fieldList.add(fieldMap.get("field"+i).split(",fh,"));	//属性放到集合里面
			    }
				
				Map<String,Object> root = new HashMap<String,Object>();		//创建数据模型
				root.put("fieldList", fieldList);
		        
		        
		        //获得模型
		        Template temp = cfg.getTemplate("sequesces.ftlh");
		        
		        Writer out = new OutputStreamWriter(System.out);
		        //将模型和数据整合
		        temp.process(root, out);
		
	}
}
